#include "stars_detection.h"
#include <stars_finder.h>
#include <QFileDialog>

stars_detection::stars_detection(QWidget *parent) :
	QWidget(parent)
{
	ui.setupUi(this);
	scene = new QGraphicsScene(ui.graphicsView);
	scene->setBackgroundBrush(QBrush(QColor(0, 0, 0)));
	ui.graphicsView->setScene(scene);
	QObject::connect(ui.pushButton, SIGNAL(clicked()), this, SLOT(get_stars()));
	get_stars();
}

stars_detection::~stars_detection()
{

}

void stars_detection::get_stars()
{
	QString path = QFileDialog::getOpenFileName(this, tr("Select image"),
			"/home/pasha", tr("Image Files (*.jpg)"));
	std::vector<cv::Point2f> stars;
	get_features(path.toStdString(), stars);
	QPixmap size_grabber(path, "JPEG");
	scene->setSceneRect(size_grabber.rect());
	for (size_t i = 0; i < stars.size(); i++)
	{
		scene->addEllipse(stars[i].x - 1, stars[i].y - 1, 2, 2, QPen(QColor(
				255, 0, 0)));
	}
	ui.graphicsView->repaint();
}
